<template>
  <!-- 添加或修改对话框 -->
  <el-dialog :close-on-click-modal="false" :before-close="beforeClose" :title="title" :visible="visible"
             width="500px"
             append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="80px" >
      <#list  columns as field>
      <el-form-item label="${field.columnComment!}" prop="${field.columnName!}">
        <el-input v-model="form.${field.columnName!}" placeholder="请输入${field.columnComment!}"/>
      </el-form-item>
    </#list>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="close">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: "${tableName}Dialog",
  props: {
    title: {
      type: String,
      default: ""
    },
    visible: {
      type: Boolean,
      default: false,
    },
    infoId: {
      type: [String, Number],
      default: "",
      required: true
    }
  },
  data() {
    return {
      form: {},
      rules: {},
    }
  },
  created() {
  },
  methods: {
    //预留的初始化函数,详情拿回来后会调用这里
    initData(data) {

    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.post('/neu/${bigModuleName}/${tableName}/upsert', this.form).then(response => {
            this.$message({
              message: '保存成功！',
              type: 'success'
            });
            this.open = false;
            this.close();
          });
        }
      });
    },
// 表单重置
    reset() {
      this.form = {
        name: null,
        code: null,
      };
      this.$refs["form"].resetFields();
    },
    close() {
      this.reset();
      this.$emit('update:visible', false)
      //告诉外面弹框关掉了，用于让外部的列表刷新一下
      this.$emit('close')
    },
    beforeClose() {
      this.close()
    }
  },
  watch: {
    infoId(id) {
      if (id) {
        this.post('/neu/${bigModuleName}/${tableName}/getById', {id}).then(response => {
          this.form = response;
        });
      }

    }
  }
}
</script>

<style scoped>

</style>
